return;
}
+ if (commands[1].startsWith("sd") ||
+ commands[1].startsWith("hd"))
+ {
+ /*
+ * this is a gross hack to allow you to create a virtual block
+ * device that maps directly to a physical partition
+ */
+
+ /* find the appropriate partition */
+ Partition partition = pm.get_partition(commands[1]);
+ if (partition == null)
+ {
+ System.out.println ("vbdcreate error: couldn't find partition \"" +
+ commands[1] + "\"");
+ return;
+ }
+
+ /* create a virtual disk */
+ vd = new VirtualDisk("vbd:" + commands[1]);
+ vd.add_new_partition(partition, partition.nr_sects);
+
+
+ /* display result */
+ System.out.print("domain:" + commands[2] + " ");
+ if (commands.length == 4)
+ {
+ System.out.print ("rw ");
+ }
+ else
+ {
+ System.out.print(commands[4] + " ");
+ }
+ System.out.print("segment:" + commands[3] + " ");
+ System.out.print(vd.dump_xen());
+ System.out.println("");
+
+ return;
+ }
+
if (commands.length == 4)
{
vbd =
commands[4]);
}
+ /* display commandline to user */
{
vd = vdm.get_virtual_disk_key(commands[1]);
System.out.println ("\n" + vd.dump_xen(vbd) + "\n");
{
if (commands.length < 3)
{
- System.out.println ("vbdcreate <domain number> <vbd number>");
+ System.out.println ("vbddelete <domain number> <vbd number>");
return;
}
import java.io.*;
import java.util.Vector;
+import java.util.Enumeration;
public class
PartitionManager
Vector partition_map;
Vector xeno_partition_list;
+ static String proc_template =
+ "major minor #blocks start_sect nr_sects name";
+
/*
* Initialize partition manager with source file.
* Normally we read from /proc/partitions, but we can
in = new BufferedReader(new FileReader(filename));
str = in.readLine(); /* skip headings */
+ if (str.length() < proc_template.length() ||
+ !str.substring(0, proc_template.length()).equals(proc_template))
+ {
+ System.err.println ("Error: Incorrect /proc/partitions.");
+ System.err.println (" Is this Xeno?");
+ System.exit (1);
+ }
+
str = in.readLine(); /* skip blank line */
str = in.readLine();
}
}
+ Partition
+ get_partition (String name)
+ {
+ Partition partition = null;
+ for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;)
+ {
+ partition = (Partition) e.nextElement();
+ if (partition.name.equals(name))
+ {
+ return partition;
+ }
+ }
+ return null;
+ }
+
Partition
get_partition (int index)
{
return sb.toString();
}
+ String
+ dump_xen ()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("extents:" + extents.size() + " ");
+ for (int loop = 0; loop < extents.size(); loop++)
+ {
+ Extent e = (Extent) extents.get(loop);
+ sb.append("(disk:" + e.disk + " " +
+ "offset:" + e.offset + " " +
+ "size:" + e.size + ")");
+ }
+ return sb.toString();
+ }
+
String
dump_xen (VirtualBlockDevice vbd)
{
public class
VirtualDiskManager
{
- VirtualDisk free;
+ VirtualDisk free_disk;
Vector virtual_disks;
Hashtable virtual_block_devices;
Hashtable key_hash;
VirtualDiskManager ()
{
- free = new VirtualDisk("free");
+ free_disk = new VirtualDisk("free");
virtual_disks = new Vector(10,5);
flush_virtual_block_devices();
public void
add_xeno_partition (Partition partition, long size)
{
- free.add_new_partition (partition, size);
+ free_disk.add_new_partition (partition, size);
return;
}
{
Extent e;
- e = free.remove_extent();
+ e = free_disk.remove_extent();
if (e == null)
{
return null;
e = vd.remove_extent();
while (e != null)
{
- free.add_extent(e);
+ free_disk.add_extent(e);
e = vd.remove_extent();
}
}
public void
add_free (VirtualDisk vd)
{
- free = vd;
+ free_disk = vd;
}
public String
public String
dump_free()
{
- return(free.dump(true, false));
+ return(free_disk.dump(true, false));
}
public String
dump_xml(PrintWriter out)
{
out.println("<free>");
- free.dump_xml(out);
+ free_disk.dump_xml(out);
out.println("</free>");
out.println("<virtual_disks>");
for (int i = 0; i < virtual_disks.size(); i++)